Results 1 to 9 of 9

Thread: Limit a returned number?

  1. #1

    Default Limit a returned number?

    I tried to search for this but i wasn't exactly sure how to even word it.. Anyway, say you have a hud that returns a RGB value

    It returns values as ( 1.000000 0.000000 1.000000 )

    The values entered into it are ( 1.0 0.0 1.0 ) but it displays extra 0's. Say I wanted to limit it to 3 digits after the decimal?

    ie : entered value ( 0.357 0.357 0.357 )
    returned value ( 0.357 0.357 0.357 ) instead of ( 0.357000 0.357000 0.357000 )

  2. #2
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Have you tried to just parse them into a float variable ?

    local.array = float local.array

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  3. #3

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    Have you tried to just parse them into a float variable ?

    local.array = float local.array
    I have not, but I did have (and removed) a random setting that used (randomfloat(0.999)) for the RGB values and it still returned with extra 0's, using randomfloat like that would make it a float variable I assume? I'm in unfamiliar waters with this project, as I've never made anything quiet like it. If I can't tweak the extra 0's I can work around it, it was just a matter of convenience. I've never messed with arrays. So let me ask, my script right now sets it's values up top, level.Fog1, level.Fog2 etc, then it a loop it checks for a certain cvar before changing fog. Could I instead create an array like

    local.Fog = makearray
    (Colors)
    (Colors)
    end array

    And then have it change via level.Fog++ every 10 seconds? Would it go through the array single file? I've tried to understand arrays but it's pretty confusing for me.
    Just trying to shorten about 2,000 lines of script lol

    But I do have another question Purple. What about character replacement? Say you have a script log things into the console, and when it logs the RGB values it prints as (0.243000, 0.423000, 0.342000)

    I see, in the strings.scr, that there is a thread that replaces "_" with spaces, but I'm not quiet understanding the script itself. I could probably just change the values and get it to replace my commas, but I'd like to also understand it for future use. I guess I just need an explanation of how this works and how to adapt it. Some of the more advanced things are still confusing to me lol. I feel like it's because of the string I'm trying to print back? I assume it'd work normal if it wasn't an RGB value?

    Edit: Also in strings saw the Remove as well, I tried using Replace_format level.Fog "," " " and Remove level.Fog ",", this stops the rest of the string after the first color, and also gets rid of the parenthesis.
    Last edited by Gotcha; July 25th, 2015 at 05:35 PM.

  4. #4
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hi

    Arrays can be confusing at first, they were for me, but now i use them all the time.
    level.Fog = makearray
    (color1)
    (color2)
    endArray

    Would make the array, and you can either loop through it for as you said, just increase the index and access it directly.
    You have it silently incorrect tho.
    level.Fog++ <<< this is not an integer so you cannot just add 1 to it. You need to increase the index. Most arrays are accessed within a for() loop, but you can use them the way you want aswell. You will just have to remember to check array size when increasing index so you dont go higher then the array size.

    So first set a variable to 0 ( starting index ) so something like
    level.fogindex = 0

    So then you access the array like
    level.Fog[level.fogindex][1]

    Should check if the index is still in the range of the array before adding to it
    if(level.fogindex < level.fog.size)
    {
    //Still good to add to it
    level.fogindex++
    }
    else
    {
    // Is at end of array, start again??
    level.fogindex = 0
    }



    Regarding the strings.scr::split_line

    When using any of those methods, you do not need to edit them yourself for them to work, all the custom parts are passed as arguments when you call the method.
    Split line will split a string into an array of words, and you can choose which character you wish to split them with, default it " " (space).

    Why it starts at 3... idk im sure Elgan can explain that one, i find them hard to follow at times lol all i know is they work and thats all that matters.

    This thread is not the one you want to use to replace characters with others. That script just parses them into an array of words.

    The one to replace characters is funnily enough call replace.
    exec global/strings::replace ( string string , string string to replace, string string to replace with )
    local.string = waitexec global/strings.scr::replace "this,is,Gotchas,mod," "," " "
    local.string would become "this is Gotchas mod"

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #5

    Default

    I've tried messing with ::Remove, ::Replace, and ::Format_replace. The only problem is that instead of replacing the "," it causes the RGB to end after the red value, it will only display up to the first "," it removes, or replaces.

    I'm obviously no expert, lol, but is it because it's trying to replace and print back a float value? something causes it to think ( 1.000000, 0.000000, 0.900000 ) should print as " 1.000000 " it removes the parenthesis and anything after the first value.

    Can you convert a float to a string? would that make it work? or am I just missing something simple?
    Last edited by Gotcha; July 25th, 2015 at 06:43 PM.

  6. #6
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Have you looked at the

    light_from_string local.string:
    thread.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  7. #7

    Default

    I have not, but I do remember seeing it at a time before I knew what it could be used for, now it seems like it may come in handy. Where can I find it? It's not in the strings.scr I have, but I saw it somewhere in something Elgan related not too long ago. I'm sure I have it, is it in a strings.scr, or a script of a different name?


    EDIT: Found it, nagle.scr
    Last edited by Gotcha; July 25th, 2015 at 07:01 PM.

  8. #8
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    He included it in the strings.scr, you just need to get the latest version. Latest is in Elgbot mod i am pretty sure

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  9. #9

    Default

    Ah, will update when I get back home.


    EDIT: You know what. You made me realize I need practice with arrays anyway, so I'm gonna toss my current method and rewrite my script using an array for each rgb value and then just have the hud and print threads use those arrays. The hud will still show with commas, but they won't print in the log.
    Last edited by Gotcha; July 25th, 2015 at 10:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •